Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
of_encoder.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_fec/target_openfec/roc_fec/of_encoder.h
10//! @brief Encoder implementation using OpenFEC library.
11
12#ifndef ROC_FEC_OF_ENCODER_H_
13#define ROC_FEC_OF_ENCODER_H_
14
15#include "roc_core/array.h"
17#include "roc_core/iallocator.h"
19#include "roc_core/slice.h"
22#include "roc_packet/units.h"
23
24extern "C" {
25#include <of_openfec_api.h>
26}
27
28#ifndef OF_USE_ENCODER
29#error "OF_USE_ENCODER undefined"
30#endif
31
32#ifndef OF_USE_LDPC_STAIRCASE_CODEC
33#error "OF_USE_LDPC_STAIRCASE_CODEC undefined"
34#endif
35
36namespace roc {
37namespace fec {
38
39//! Encoder implementation using OpenFEC library.
40class OFEncoder : public IBlockEncoder, public core::NonCopyable<> {
41public:
42 //! Initialize.
43 explicit OFEncoder(const CodecConfig& config,
44 core::BufferPool<uint8_t>& buffer_pool,
45 core::IAllocator& allocator);
46
47 virtual ~OFEncoder();
48
49 //! Check if object is successfully constructed.
50 bool valid() const;
51
52 //! Get buffer alignment requirement.
53 virtual size_t alignment() const;
54
55 //! Get the maximum number of encoding symbols for the scheme being used.
56 virtual size_t max_block_length() const;
57
58 //! Start block.
59 //!
60 //! @remarks
61 //! Performs an initial setup for a block. Should be called before
62 //! any operations for the block.
63 virtual bool begin(size_t sblen, size_t rblen, size_t payload_size);
64
65 //! Store packet data for current block.
66 virtual void set(size_t index, const core::Slice<uint8_t>& buffer);
67
68 //! Fill repair packets.
69 virtual void fill();
70
71 //! Finish block.
72 //!
73 //! @remarks
74 //! Cleanups the resources allocated for the block. Should be called after
75 //! all operations for the block.
76 virtual void end();
77
78private:
79 bool resize_tabs_(size_t size);
80 void reset_session_();
81 void update_session_params_(size_t sblen, size_t rblen, size_t payload_size);
82
83 enum { Alignment = 8 };
84
85 size_t sblen_;
86 size_t rblen_;
87
88 size_t payload_size_;
89
90 of_session_t* of_sess_;
91 of_parameters_t* of_sess_params_;
92
93 of_codec_id_t codec_id_;
94 union {
95 of_ldpc_parameters ldpc_params_;
96 of_rs_2_m_parameters_t rs_params_;
97 } codec_params_;
98
100 core::Array<void*> data_tab_;
101
102 size_t max_block_length_;
103
104 bool valid_;
105};
106
107} // namespace fec
108} // namespace roc
109
110#endif // ROC_FEC_OF_ENCODER_H_
Dynamic array.
Buffer pool.
Dynamic array.
Definition: array.h:25
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Slice.
Definition: slice.h:23
FEC block encoder interface.
Encoder implementation using OpenFEC library.
Definition: of_encoder.h:40
virtual void fill()
Fill repair packets.
virtual void set(size_t index, const core::Slice< uint8_t > &buffer)
Store packet data for current block.
virtual bool begin(size_t sblen, size_t rblen, size_t payload_size)
Start block.
bool valid() const
Check if object is successfully constructed.
virtual size_t alignment() const
Get buffer alignment requirement.
virtual size_t max_block_length() const
Get the maximum number of encoding symbols for the scheme being used.
OFEncoder(const CodecConfig &config, core::BufferPool< uint8_t > &buffer_pool, core::IAllocator &allocator)
Initialize.
virtual void end()
Finish block.
FEC codec parameters.
Memory allocator interface.
FEC block encoder interface.
Root namespace.
Non-copyable object.
Various units used in packets.
Slice.
FEC codec parameters.
Definition: codec_config.h:22